﻿{extend name="public:base" /}{block name="css"}
<link href="/static/laydate/theme/default/laydate.css">
<style>
    .status-box {
        margin-top: 10px;
        background: #e9ecef;
        display: flex;
        align-items: center;
    }

    .margin-top-5 {
        margin-top: 5px;
    }

    .label-margin {
        margin-right: 10px !important;
        margin-bottom: 0 !important;
    }

    .red {
        color: red;
    }

    tbody a {
        color: #7e8183 !important;
    }
</style>{/block}{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <div class="row search-form">
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请输入手机号" name="mobile" value="{:input('mobile')}" type="text" class="form-control form-control-lg">
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请输入企业名称" name="company_name" value="{:input('company_name')}" type="text" class="form-control form-control-lg">
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="user_type" class="form-control form-control-lg">
                                    <option value="0">请选择用户身份</option>
                                    <option value="1" {:input('user_type') == 1 ? 'selected' : ''}>供应商</option>
                                    <option value="2" {:input('user_type') == 2 ? 'selected' : ''}>渠道商</option>
                                    <option value="3" {:input('user_type') == 3 ? 'selected' : ''}>业务员</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <select name="status" class="form-control form-control-lg">
                                    <option value="0">请选择认证审核状态</option>
                                    <option value="1" {:input('status') == 1 ? 'selected' : ''}>待审核</option>
                                    <option value="2" {:input('status') == 2 ? 'selected' : ''}>已通过</option>
                                    <option value="3" {:input('status') == 3 ? 'selected' : ''}>已驳回</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <input placeholder="请选择日期" type="text" name="date_range" value="{:input('date_range')}" class="form-control form-control-lg screen-date" readonly>
                            </div>
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group" style="width: 100%; display: flex; justify-content: space-between">
                                <button type="button" class="btn btn-primary btn-lg screen-btn">搜索</button>
                                <a href="{:url('resetQr')}" type="button" class="btn btn-primary btn-lg ajax-operate">一键重置小程序码</a>
                            </div>
                        </div>
                    </div>

                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>头像</th>
                                <th>昵称</th>
                                <th>手机号</th>
                                <th>企业名称</th>
                                <th>渠道商评分</th>
                                <th>渠道商服务类目</th>
                                <th>业务员评分</th>
                                <th>业务员等级</th>
                                <th>供应商信息</th>
                                <th>渠道商信息</th>
                                <th>业务员信息</th>
                                <th>注册时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr class="{$vo.channel_is_normal == 0 ? 'red' : ''}">
                                <td>{$vo.id}</td>
                                <td>
                                    <img src="{$vo.avatar == '../../static/images/avatar.png' ? '__ADMIN__/img/avatar.png' : $vo.avatar}" style="width: 100px;height: 100px; object-fit: cover; border-radius: 50%"/>
                                </td>
                                <td>{$vo.username}</td>
                                <td>{$vo.mobile}</td>
                                <td>{$vo.company_name}</td>
                                <td>{$vo.channel_score}</td>
                                <td>{$vo.channel_type_name}</td>
                                <td>{$vo.salesman_score}</td>
                                <td>{$vo.salesman_id > 0 ? doSalesmanLevel($vo.salesman_score) : ''}</td>
                                <td class="project-actions">
                                    {if $vo.supplier_id > 0}
                                    <a href="javascript: void(0)" class="btn btn-white btn-sm" onclick="initInfo(`supplier`,`{$vo.ident_list.supplier_info.id}`,`{$vo.ident_list.supplier_info.username}`, `{$vo.ident_list.supplier_info.mobile}`, `{$vo.ident_list.supplier_info.status}`, `{$vo.ident_list.supplier_info.company_name}`, `{$vo.ident_list.supplier_info.yyzz_img}`)" data-toggle="modal" data-target="#supplier-box">
                                        <i class="iconfont icon-eye"></i> 查看信息<span style="color: red">{$vo.ident_list.supplier_info.status == 0 ? '（待审核）' : ''}</span>
                                    </a>
                                    {/if}
                                </td>
                                <td class="project-actions">
                                    {if $vo.channel_id > 0}
                                    {if $vo.channel_is_normal == 0}
                                    <span>接单状态异常</span>
                                    <br>
                                    <a href="javascript: void(0)" class="btn btn-white btn-sm" onclick="initPunishId('{$vo.id}')" data-toggle="modal" data-target="#punish-box">
                                        <i class="iconfont icon-quanxianpeizhi"></i> 处罚</span>
                                    </a>
                                    <br>
                                    {else /}
                                    <a href="javascript: void(0)" class="btn btn-white btn-sm" onclick="initInfo(`channel`,`{$vo.ident_list.channel_info.id}`,`{$vo.ident_list.channel_info.username}`, `{$vo.ident_list.channel_info.mobile}`, `{$vo.ident_list.channel_info.status}`, `{$vo.ident_list.channel_info.company_name}`, `{$vo.ident_list.channel_info.yyzz_img}`)" data-toggle="modal" data-target="#channel-box">
                                        <i class="iconfont icon-eye"></i> 查看信息<span style="color: red">{$vo.ident_list.channel_info.status == 0 ? '（待审核）' : ''}</span>
                                    </a>
                                    <br>
                                    <a href="javascript: void(0)" class="btn btn-white btn-sm margin-top-5" onclick="initServiceTypes(`{$vo.id}`,`{$vo.channel_type_ids}`)" data-toggle="modal" data-target="#channel-service-box">
                                        <i class="iconfont icon-tasks"></i> 服务类目
                                    </a>
                                    {/if}
                                    {/if}
                                </td>
                                <td class="project-actions">
                                    {if $vo.salesman_id > 0}
                                    <a href="javascript: void(0)" class="btn btn-white btn-sm" onclick="initInfo(`salesman`,`{$vo.ident_list.salesman_info.id}`,`{$vo.ident_list.salesman_info.username}`, `{$vo.ident_list.salesman_info.mobile}`, `{$vo.ident_list.salesman_info.status}`)" data-toggle="modal" data-target="#salesman-box">
                                        <i class="iconfont icon-eye"></i> 查看信息<span style="color: red">{$vo.ident_list.salesman_info.status == 0 ? '（待审核）' : ''}</span>
                                    </a>
                                    {/if}
                                </td>
                                <td>{:timeFormat($vo.create_time, 'Y-m-d')}</td>
                                <td class="project-actions">
                                    {if $vo.channel_id > 0}
                                    <a href="{:url('userList', ['up_channel_user_id' => $vo.id])}" class="btn btn-white btn-sm">
                                        <i class="iconfont icon-users"></i> 业务员列表
                                    </a>
                                    <br>
                                    {/if}
                                    {if $vo.salesman_id > 0}
                                    <a href="{:url('userList', ['up_salesman_user_id' => $vo.id])}" class="btn btn-white btn-sm margin-top-5">
                                        <i class="iconfont icon-users"></i> 客户列表
                                    </a>
                                    <br>
                                    <a href="{:url('integralList', ['user_id' => $vo.id])}" class="btn btn-white btn-sm margin-top-5">
                                        <i class="iconfont icon-news"></i> 积分明细
                                    </a>
                                    <br>
                                    <a href="{:url('doUserIntegral', ['id' => $vo.id])}" class="btn btn-white btn-sm margin-top-5" onclick="setUserIntegralId(`{$vo.id}`, `{$vo.integral}`)" class="btn btn-white btn-sm" data-toggle="modal" data-target="#user-integral-box">
                                        <i class="iconfont icon-change"></i> 积分管理
                                    </a>
                                    {/if}
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        {if !empty($list)}{$list->render()}{/if}
                    </div>

                </div>
            </div>
        </div>

    </div>

    <div class="modal inmodal" id="supplier-box" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">供应商信息</h4>
                </div>
                <div class="modal-body">
                    <input type="text" class="form-control company_name" readonly>
                    <img class="yyzz_img" style="width: 100px; height: 100px; margin-top: 10px; object-fit: cover" onclick="previewImg(this, 'yyzz_img')" src="" alt="">
                    <input type="text" class="form-control username" readonly style="margin-top: 10px">
                    <input type="text" class="form-control mobile" readonly style="margin-top: 10px">
                    <input type="text" class="form-control status_desc" readonly style="margin-top: 10px">
                    <div class="form-control layui-form status-box">
                        <label class="label-margin">
                            <input type="radio" class="supplier-status" name="supplier-status" value="0" checked>
                            待审核
                        </label>
                        <label class="label-margin">
                            <input type="radio" class="supplier-status" name="supplier-status" value="1">
                            通过
                        </label>
                        <label style="margin-bottom: 0;">
                            <input type="radio" class="supplier-status" name="supplier-status" value="2">
                            驳回
                        </label>
                    </div>
                    <input type="text" class="form-control remark" placeholder="请输入驳回原因" style="margin-top: 10px; display: none">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white close-model" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary status-btn" onclick="confirmStatus('supplier-box')">确认审核</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal" id="channel-box" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">渠道商信息</h4>
                </div>
                <div class="modal-body">
                    <input type="text" class="form-control company_name" readonly>
                    <img class="yyzz_img" style="width: 100px; height: 100px; margin-top: 10px; object-fit: cover" onclick="previewImg(this, 'yyzz_img')" src="" alt="">
                    <input type="text" class="form-control username" readonly style="margin-top: 10px">
                    <input type="text" class="form-control mobile" readonly style="margin-top: 10px">
                    <input type="text" class="form-control status_desc" readonly style="margin-top: 10px">
                    <div class="form-control layui-form status-box">
                        <label class="label-margin">
                            <input type="radio" class="channel-status" name="channel-status" value="0" checked>
                            待审核
                        </label>
                        <label class="label-margin">
                            <input type="radio" class="channel-status" name="channel-status" value="1">
                            通过
                        </label>
                        <label style="margin-bottom: 0;">
                            <input type="radio" class="channel-status" name="channel-status" value="2">
                            驳回
                        </label>
                    </div>
                    <input type="text" class="form-control remark" placeholder="请输入驳回原因" style="margin-top: 10px; display: none">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white close-model" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary status-btn" onclick="confirmStatus('channel-box')">确认审核</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal" id="channel-service-box" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">渠道商服务类目信息</h4>
                </div>
                <div class="modal-body channel_type_ids_box"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white close-model" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary status-btn" onclick="confirmTypes()">确认</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal" id="punish-box" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">处罚渠道商</h4>
                </div>
                <div class="modal-body">
                    <select class="form-control" id="punish-type">
                        <option value="0">请选择处罚类型</option>
                        <option value="1">扣评分</option>
                        <option value="2">禁止接单</option>
                    </select>
                    <input type="text" class="form-control score" placeholder="请输入扣除评分数值" style="margin-top: 10px; display: none" />
                    <input type="text" class="form-control day" placeholder="请输入禁止接单天数" style="margin-top: 10px; display: none" />
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white close-model" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary status-btn" onclick="confirmPunish()">确认</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal" id="salesman-box" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">业务员信息</h4>
                </div>
                <div class="modal-body">
                    <input type="text" class="form-control username" readonly style="margin-top: 10px">
                    <input type="text" class="form-control mobile" readonly style="margin-top: 10px">
                    <input type="text" class="form-control status_desc" readonly style="margin-top: 10px">
                    <div class="form-control layui-form status-box">
                        <label class="label-margin">
                            <input type="radio" class="salesman-status" name="salesman-status" value="0" checked>
                            待审核
                        </label>
                        <label class="label-margin">
                            <input type="radio" class="salesman-status" name="salesman-status" value="1">
                            通过
                        </label>
                        <label style="margin-bottom: 0;">
                            <input type="radio" class="salesman-status" name="salesman-status" value="2">
                            驳回
                        </label>
                    </div>
                    <input type="text" class="form-control remark" placeholder="请输入驳回原因" style="margin-top: 10px; display: none">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white close-model" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary status-btn" onclick="confirmStatus('salesman-box')">确认审核</button>
                </div>
            </div>
        </div>
    </div>


    <div class="modal inmodal" id="user-integral-box" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">积分管理</h4>
                </div>
                <div class="modal-body">
                    <input type="text" class="form-control user_integral" readonly value="">
                    <input type="number" class="form-control integral" placeholder="请输入积分；正数表示增加积分，负数表示扣除积分" style="margin-top: 10px">
                    <input type="text" class="form-control remark" placeholder="请输入备注" style="margin-top: 10px">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white close-model" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="save">确认</button>
                </div>
            </div>
        </div>
    </div>

</div>
{include file="public/preview-img-mask" swiper-id="cropper-preview" /}
{/block}

{block name="js"}
<script src="/static/laydate/laydate.js"></script>
<script>
    laydate.render({
        elem: '.screen-date', //指定元素
        format: 'yyyy-MM-dd',
        range: true
    });

    var ident_id = 0;

    function initInfo(user_type, ident_key_id, username, mobile, status, company_name = '', yyzz_img = '') {
        ident_id = ident_key_id;
        var status_desc = '';
        switch (parseInt(status)) {
            case 0:
                status_desc = '待审核';
                break;
            case 1:
                status_desc = '已通过';
                break;
            case 2:
                status_desc = '已驳回';
                break;
        }

        if (user_type == 'supplier') {
            $('#supplier-box .company_name').val(company_name);
            $('#supplier-box .yyzz_img').attr('src', yyzz_img);
            $('#supplier-box .username').val(username);
            $('#supplier-box .mobile').val(mobile);
            if (status == 0) {
                $('#supplier-box .status-box').attr('display', 'flex');
                $('#supplier-box .status_desc').hide();
            } else {
                $('#supplier-box .status-box').hide();
                $('#supplier-box .status_desc').val(status_desc).show();
                $('#supplier-box .status-btn').hide();
            }
        } else if (user_type == 'channel') {
            $('#channel-box .company_name').val(company_name);
            $('#channel-box .yyzz_img').attr('src', yyzz_img);
            $('#channel-box .username').val(username);
            $('#channel-box .mobile').val(mobile);
            if (status == 0) {
                $('#channel-box .status-box').attr('display', 'flex');
                $('#channel-box .status_desc').hide();
            } else {
                $('#channel-box .status-box').hide();
                $('#channel-box .status_desc').val(status_desc).show();
                $('#channel-box .status-btn').hide();
            }
        } else {
            $('#salesman-box .username').val(username);
            $('#salesman-box .mobile').val(mobile);
            if (status == 0) {
                $('#salesman-box .status-box').attr('display', 'flex');
                $('#salesman-box .status_desc').hide();
            } else {
                $('#salesman-box .status-box').hide();
                $('#salesman-box .status_desc').val(status_desc).show();
                $('#salesman-box .status-btn').hide();
            }
        }
    }

    $('.supplier-status').click(() => {
        var status = $('.supplier-status:checked').val();
        clickRadio(status, 'supplier-box');
    })

    $('.channel-status').click(() => {
        var status = $('.channel-status:checked').val();
        clickRadio(status, 'channel-box');
    })

    $('.salesman-status').click(() => {
        var status = $('.salesman-status:checked').val();
        clickRadio(status, 'salesman-box');
    })

    var status = 0;

    function clickRadio(choose_status, id_name) {
        if (choose_status == 2) {
            $('#' + id_name + ' .remark').show();
        } else {
            $('#' + id_name + ' .remark').hide();
        }
        status = choose_status;
    }

    function confirmStatus(id_name) {
        var id = ident_id;
        var status = $('#' + id_name + ' input:radio:checked').val();
        var remark = $('#' + id_name + ' .remark').val();

        if (status == 2 && remark == '') {
            layer.msg('请输入驳回原因', {icon: 2, time: 1000});
            return false;
        }

        $.post('/admin/manage/identConfirmStatus', {
            id, status, remark
        }, res => {
            if (res.result == 1) {
                layer.msg(res.msg, {icon: 1, time: 1000});
                setTimeout(() => {
                    window.location.reload()
                }, 1000)
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'JSON')
    }

    var user_id = 0;

    function initPunishId(id){
        user_id = id
    }

    $('#punish-type').change(function (){
        var type = $(this).val();
        if(type == 1){
            $('#punish-box .score').show();
            $('#punish-box .day').hide().val('');
        }else if(type == 2){
            $('#punish-box .score').hide().val('');
            $('#punish-box .day').show();
        }else{
            $('#punish-box .score').hide().val('');
            $('#punish-box .day').hide().val('');
        }
    })

    function confirmPunish(){
        var punish = $('#punish').val();
    }

    function initServiceTypes(id, channel_type_ids) {
        user_id = id;
        var service_type_list = {$service_type_list} || [];
        var channel_type_ids_array = channel_type_ids ? channel_type_ids.split(',') : [];

        if (service_type_list.length) {
            var checkbox_html = '';
            service_type_list.forEach((val) => {
                if (channel_type_ids_array.length > 0) {
                    var checked = channel_type_ids_array.indexOf(val.id.toString()) != -1 ? 'checked' : '';
                } else {
                    var checked = '';
                }

                checkbox_html += `<label class="label-margin">
                            <input type="checkbox" class="channel_type_ids" name="channel_type_ids[]" value="${val.id}" ${checked}>
                            ${val.name}
                        </label>`;
            })
            $('.channel_type_ids_box').html(checkbox_html)
        }
    }

    function confirmTypes() {
        var channel_type_ids = [];
        $("input[name='channel_type_ids[]']").each(function () {
            if ($(this).is(':checked')) {
                channel_type_ids.push(parseInt($(this).val()));
            }
        })

        if (channel_type_ids.length > 0) {
            channel_type_ids = channel_type_ids.join(',');
        } else {
            channel_type_ids = '';
        }

        $.post('/admin/manage/saveChannelTypeIds', {user_id, channel_type_ids}, res => {
            if (res.result == 1) {
                layer.msg(res.msg, {icon: 1, time: 1000});
                setTimeout(() => {
                    window.location.reload();
                }, 1000)
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'JSON')
    }

    var id = 0;

    function setUserIntegralId(user_id, user_integral) {
        id = user_id;
        $('#user-integral-box .user_integral').val('当前账户积分：' + user_integral);
    }

    $('#save').click(() => {
        var integral = $('#user-integral-box .integral').val();
        var remark = $('#user-integral-box .remark').val();

        if (integral == 0) {
            layer.msg('请输入积分', {icon: 2, time: 1000});
            return false;
        }
        if (remark == '') {
            layer.msg('请输入备注', {icon: 2, time: 1000});
            return false;
        }

        $.post('/admin/manage/setUserIntegral', {
            id: id, integral, remark
        }, res => {
            if (res.result == 1) {
                layer.msg(res.msg, {icon: 1, time: 1000});
                setTimeout(() => {
                    window.location.reload()
                }, 1000)
            } else {
                layer.msg(res.msg, {icon: 2, time: 1000});
            }
        }, 'JSON')
    })
</script>{/block}

